/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sdd.facades.business;

import com.sdd.entities.Customer;
import com.sdd.facades.persistence.CustomerPersistenceFacade;
import com.sdd.plains.CustomerPlain;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

/**
 *
 * @author T
 */

@Stateless
@LocalBean
public class CustomerBusinessFacadeBean {
    @EJB
    CustomerPersistenceFacade customerPersistenceFacade;
    
    public Customer getCustomer(Long id){
        return customerPersistenceFacade.find(id);
    }
    
    public Customer getCustomerbyLogin(String login){
        return customerPersistenceFacade.getCustomerbyLogin(login);
    }
    
    public Customer getCustomerbyEmail(String email){
       return customerPersistenceFacade.getCustomerbyEmail(email);
    }
    
    public boolean existLogin(String login){
       return customerPersistenceFacade.existLogin(login);
    }
    
    public boolean existEmail(String email){
         return customerPersistenceFacade.existEmail(email);
    }
    
    public List<Customer> getAllCustomers(){
        return customerPersistenceFacade.findAll();
    }
    
    public Customer addCustomer(CustomerPlain plain){
        Customer c = new Customer();
        c.setId(plain.getId());
        c.setEmail(plain.getEmail());
        c.setFirstname(plain.getFirstname());
        c.setLastname(plain.getLastname());
        c.setLogin(plain.getLogin());
        c.setPass(plain.getPass()); 
        return customerPersistenceFacade.create(c);
    }
    
    public Customer addCustomer(Customer entity){
        return customerPersistenceFacade.create(entity);
    }
 

    
}
